<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div>
            <header style="height: 100%">
                <div align="left">
                    <table style="width: 100%">
                        <tr>
                            <!--<td>-->
                            <!--<form class="form-inline" onsubmit="return false">-->
                            <!--<div class="form-group">-->
                            <!--id：-->
                            <!--<input id="id" type="text" class="form-control" placeholder="id">-->

                            <!--<button id="searchBt" class="layui-btn layui-btn-sm"-->
                            <!--permission="sys:orders:query"><i class="layui-icon">&#xe615;</i>搜索</button>-->

                            <!--</div>-->

                            <!--</form>-->
                            <!--</td>-->

                            <td align="right">
                                <button class="layui-btn layui-btn-sm" onclick="updateOrderState();">
                                    <i class="layui-icon">&#xe608;</i> 修正订单
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </header>

            <div>
                <div class="widget-body no-padding">
                    <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                        <thead>
                        <tr>
                        </tr>
                        <tr>
                            <th>id</th>
                            <th>用户id</th>
                            <th style="width: 70px;">昵称</th>
                            <th>咨询id</th>
                            <!--<th>交易单号</th>-->
                            <th>交易单号</th>
                            <th>服务名称</th>
                            <th>服务类型</th>
                            <th>金额</th>
                            <th>创建时间</th>
                            <th>付款状态</th>
                            <th>微信回调状态</th>
                            <th>咨询状态</th>
                            <!--<th>操作</th>-->
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
    var pers = checkPermission();

    var example;

    function init() {
        example =
            $('#dt-table').on('preXhr.dt', function (e, settings, data) {
                var columns = data.columns;
                for (var i = 0; i < columns.length; i++) {
                    if (columns[i].name) {
                        data.columns[i].data = columns[i].name;
                    }
                }
            }).DataTable({
                "searching": false,
                "processing": false,
                "serverSide": true,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/mfflOrders",
                    "type": "get",
                    "data": function (d) {
                        d.id = $("#id").val();
                        d.state = 5;
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {"data": "id", "defaultContent": ""},
                    {"data": "userid", "defaultContent": ""},
                    {"data": "nickname", "defaultContent": ""},
                    {"data": "productId", "defaultContent": "", "name": "product_id"},
                    // {"data": "payNumber", "defaultContent": "", "name": "pay_number"},
                    {"data": "payMerchantNumber", "defaultContent": "", "name": "pay_merchant_number"},
                    {"data": "servierNames", "defaultContent": ""},
                    {"data": "typeName", "defaultContent": ""},
                    {"data": "money", "defaultContent": ""},
                    {"data": "createTime", "defaultContent": ""},
                    {
                        "data": "state",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return "支付中";
                        }
                    },
                    {
                        "data": "wxState",
                        "defaultContent": "",
                        "render": function (data, type, row) {

                            var createTime = row['createTime'];
                            var createTimeNew = new Date(createTime).getTime();
                            console.log(createTimeNew);
                            var nowDate = new Date().getTime();
                            if ((nowDate - createTimeNew) > 86400000) {
                                return "超过回调时间";
                            } else {
                                return "未超过回调时间";
                            }

                            // if (createTimeNew > nowDate ){
                            //     return "超过回调时间";
                            // } else {
                            //     return "未超过回调时间";
                            // }

                        }
                    },

                    {
                        "data": "deleteStae",
                        "name": "delete_stae",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            var flag = row['deleteStae'];
                            if (flag == "0") {
                                return "关闭";
                            } else if (flag == 1) {
                                return "正常";
                            }
                        }
                    },
                    // {
                    // 				"data": "",
                    // 				"defaultContent": "",
                    // 				"orderable":false,
                    // 		        "render": function (data, type, row) {
                    // 		           var id = row['id'];
                    // 		           var del = buttonClose(id, "sys:orders:del", pers);
                    //                    return  del;
                    //   	            }
                    // 			},

                ],
                "order": [[0, "asc"]]
            });
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });


    function updateOrderState() {

        layer.confirm('确认修正订单吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'post',
                url: '/mfflOrders/updateOrderState',
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (data.errorCode == '200') {
                        layer.msg("处理完成");
                    } else {
                        layer.msg(data.message);
                    }
                    example.ajax.reload();
                }
            });

            layer.close(1);
        });


    }

    $("#searchBt").click(function () {
        example.ajax.reload();
    });


    init();
</script>
